package com.ljk.controller;

import com.ljk.domain.ResponseResult;
import com.ljk.service.UploadService;
import com.ljk.utils.MultipartFileToFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
public class UploadController {
    @Autowired
    private UploadService uploadService;
    @Value("${server.address}")
    private String address;
    @Value("${server.port}")
    private String port;
    @PostMapping("/upload")
    public ResponseResult ossUpload(MultipartFile img){
        String s = MultipartFileToFile.saveMultipartFile(img, "front-module/src/main/resources/static/imgs");
        String url="http://"+address+":"+port+"/imgs/"+s;
        return ResponseResult.okResult(url);
    }
}
